#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    pair<int, int> doublefind(string& s, int x)
    {
        int left = x;
        int right = x + 1;
        while (left >= 0 && right < s.size())
        {
            if (s[left] != s[right])
            {
                break;
            }
            left--;
            right++;
        }
        return make_pair(left + 1, right - 1);
    }
    pair<int, int> singlefind(string& s, int x)
    {
        int left = x - 1;
        int right = x + 1;
        while (left >= 0 && right < s.size())
        {
            if (s[left] != s[right])
            {
                break;
            }
            left--;
            right++;
        }
        return make_pair(left + 1, right - 1);
    }
    string longestPalindrome(string s) {
        pair<int, int> max = make_pair(0, 0);
        for (int i = 0; i < s.size(); i++)
        {
            pair<int, int> d = doublefind(s, i);
            pair<int, int> o = singlefind(s, i);
            if (d.second - d.first > max.second - max.first) max = d;
            if (o.second - o.first > max.second - max.first) max = o;
        }
        string ret;
        for (int i = max.first; i <= max.second; i++)
        {
            ret.push_back(s[i]);
        }
        return ret;
    }
};